//
//  LKRateSettingViewController.m
//  Mideleague_Agent
//
//  Created by Zhiwang on 2020/6/9.
//  Copyright © 2020 Zhiwang. All rights reserved.
//

#import "LKRateSettingViewController.h"
#import "LKMyShopOpenRateSettingCell.h"
@interface LKRateSettingViewController ()<UITableViewDelegate,UITableViewDataSource>

@property(nonatomic,strong)LKBaseTableview *tableView;
@property(nonatomic,strong)NSArray *titlesArray;
@property(nonatomic,strong)NSArray *ratesArray;
@property(nonatomic,copy)NSString *bottomStr;
@end

@implementation LKRateSettingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.bottomStr = @"";
    self.navigationItem.title = @"我的费率";
    self.titlesArray = @[@"微信",@"支付宝",@"一千元以上(借记)",@"一千元以上(贷记)",@"一千元以下"];
    [self getDetailInformationAccoringUid:[LKUserInforTool account].uid];
    [self createTableview];
//    [self getRateInformationDetail];
    // Do any additional setup after loading the view.
}

-(void)createTableview{
    self.tableView = [LKBaseTableview setTableviewWithFrame:CGRectZero style:UITableViewStyleGrouped registercellClasss:@[@"LKMyShopOpenRateSettingCell"]];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
    _tableView.backgroundColor = viewDefualtColor;
    [self.view addSubview:_tableView];
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.view);
        make.top.equalTo(self.view).offset(NAVIGATION_BAR_HEIGHT);
        make.bottom.equalTo(self.view).offset(0);
    }];
    if (@available(iOS 11.0, *)) {
        self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    } else {
        // Fallback on earlier versions
    }
    self.tableView.scrollEnabled = NO;
    [self.tableView reloadData];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return self.titlesArray.count;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    LKMyShopOpenRateSettingCell *cell = [tableView dequeueReusableCellWithIdentifier:@"LKMyShopOpenRateSettingCell"];
    cell.headerLabel.text = self.titlesArray[indexPath.section];
    cell.values = self.ratesArray[indexPath.section];
    cell.textField.userInteractionEnabled = NO;
    if (self.isMineIn) {
        cell.isHidden = YES;
    }
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 60.0f;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *header = [[UIView alloc] init];
    for (UIView *subViews in header.subviews) {
        [subViews removeFromSuperview];
    }
    if (section == 2) {
        LKBaseLabel *headerLabel = [LKBaseLabel labelWithFrame:CGRectZero text:@"云闪付费率(借记卡、贷记卡)" textColor:COLOR_HEX(0x666666) font:[UIFont fontWithName:@"PingFangSC-Regular" size:16] textAlignment:NSTextAlignmentLeft];
        [header addSubview:headerLabel];
        [headerLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(header);
            make.left.equalTo(header).offset(10);
        }];
        if (self.isMineIn) {
            headerLabel.text = @"云闪付";
            headerLabel.textColor = [UIColor blackColor];
            header.backgroundColor = [UIColor whiteColor];
        }
        return header;
    }
    return header;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{

    if (self.isMineIn) {
        if (section == 0 || section == 1) {
            return 10.0f;
        }
        if (section == 2) {
            return 60.0f;
        }
        return 1.0f;
    }else{
        if (section == 0 || section == 1) {
            return 10.0f;
        }
        if (section == 2) {
            return 60.0f;
        }
       return 0.00000000001f;
    }
    return 0.00000000001f;
}
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView *footerView = [[UIView alloc] init];
    return footerView;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0.0000000001f;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

}

/// 根据uid返回详细信息
/// @param uid 商户ID
-(void)getDetailInformationAccoringUid:(NSString *)uid{
        [SVProgressHUD showWithStatus:@""];
        NSMutableDictionary *param = [[NSMutableDictionary alloc] initWithDictionary:@{@"is_own":@"1"}];
        NSString *sign = [NSString encoingWithDic:param];
        [param setObject:sign forKey:@"sign"];
        [[LKNetDataManager defaultManager] sendRequestMethod:HTTPMethodPOST serverUrl:ServerlUrl apiPath:MyRateUrl header:[LKUserInforTool account].token parameters:param progress:^(NSProgress * _Nullable progress) {
            
        } success:^(BOOL isSuccess, id  _Nullable responseObject) {
            [SVProgressHUD dismiss];
            if ([responseObject[@"code"] isEqualToString:@"success"]) {
                self.inforModel = [LKMyShopOpenInforModel modelWithDictionary:responseObject[@"data"]];
                if (self.inforModel.ysf2_rate.length == 0) {
                    self.inforModel.ysf2_rate = self.inforModel.ysf1_rate;
                }
                self.ratesArray = @[self.inforModel.wx_rate,self.inforModel.zfb_rate,self.inforModel.ysf2_rate,self.inforModel.ysf_rate,self.inforModel.ysf1_rate];
                [self.tableView reloadData];
            }else{
                [SVProgressHUD showInfoWithStatus:responseObject[@"msg"]];
            }
        } failure:^(NSString * _Nullable errorMessage) {
            
        }];
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
